package org.bao.demo.rabbitmq;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @ClassName MqFactory
 * @Description 消息工具类
 * @Author bai
 * @Date 2021/7/21 0:09
 * @Version 1.0
 **/
public class MqFactory {

    public static Connection getConnection() throws IOException, TimeoutException {
        return FACTORY.newConnection();
    }

    private static final ConnectionFactory FACTORY = getConnectionFactory();

    /**
     * 链接工厂获取
     *
     * @return {@link ConnectionFactory }
     * @author bai
     * @date 2021/7/20 23:42
     */
    private static ConnectionFactory getConnectionFactory() {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        factory.setPort(5672);
        factory.setUsername("admin");
        factory.setPassword("admin");
        return factory;
    }
}
